import Vue from 'vue'
import 'es6-promise/auto';
import  Vuex from "vuex";
import axios from 'axios';
import cors from 'cors';

// Vue.prototype.$axios = axios
// axios.defaults.baseURL = '/api'  //关键代码

Vue.use(Vuex)


Vue.config.productionTip = false




// 创建仓库
let store = new Vuex.Store({
  state:{
    count:100,
    sxt:{
        company:'尚学堂',
        location:'14街',
        category:['web','java','大数据']
    },
    ChengPinInfo:{}
  },
  //操作状态的方法
  mutations:{
    // increment(state,num){
    //     state.count+=num
    // },
    // increment(state,payload){
    //     state.count+=payload.num
    increment(state,{num}){
        state.count+=num
    },
    
    decrement(state,num){
        state.count-=num
    },
    teachSxt(state){
        Vue.set(state.sxt,'teachNum','50个老师')
    },
    changeChengPinInfo(state,obj){
        state.ChengPinInfo = obj
    }
  },
  actions:{
      asyncIncrement(context,num){
          console.log("点击了增加")
          context.commit('increment',num)
      },
      asyncDecrement({commit},num){
          console.log("点击了减少")
        commit('decrement',num)
      },
      asyncChangeChengPinInfo({commit}){
            console.log(111)
            //   axios.get("http://www.baidu.com").then(res=>{
            axios.get("http://iwenwiki.com/api/blueburrypai/getChengPinInfo.php").then(res=>{
                console.log(res.data);
                commit('changeChengPinInfo',res.data)
              
            })
      }

  }
})

new Vue({
    store
})
export default store